//
//  HQValanceViewController.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/6/19.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQValanceViewController.h"

@interface HQValanceViewController ()

@end

@implementation HQValanceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"下联计算";
    
//    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemTitle:@"搜索" withTitleColor:[self colorHexValue:0x647180] withFont:16 withTarget:self withSelector:@selector(rightSearch)];
    
    // 下拉刷新
    _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self searchStyle];
    }];
    [_collectionView.mj_header beginRefreshing];
    _layOut.minimumInteritemSpacing = 5;
    _layOut.sectionInset = UIEdgeInsetsMake(10, 10, 5, 10);
    _layOut.itemSize = CGSizeMake(((SCREEN_WIDTH-25)/2) ,((SCREEN_WIDTH)/2)*1.1);
}

//-(void)rightSearch{
//    NSLog(@"用户点击了搜索按钮");
//}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _dataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HQValanceCollViewCell *cell = [HQValanceCollViewCell cellWithCollectionView:collectionView withIndexPath:indexPath];
    NSDictionary *dic = _dataSource[indexPath.row];
    [cell.itemImage setImageWithURL:[NSURL URLWithString:dic[@"txl_img"]] placeholderImage:[UIImage imageNamed:dic[@"app_icon"]]];
    cell.itemTitle.text = dic[@"txl_name"];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSDictionary *dict = _dataSource[indexPath.row];
    NSInteger txl_id = [dict[@"txl_id"]integerValue];
    switch (txl_id) {
        case 1:{
            HQValanceSearchViewController *valanceSearchVc = [[HQValanceSearchViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
         
        case 2:{
            HQValanceSearchTwoViewController *valanceSearchVc = [[HQValanceSearchTwoViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
        
        case 3:{
            HQValanceSearchThreeViewController *valanceSearchVc = [[HQValanceSearchThreeViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 4:{
            HQValanceSearchFourViewController *valanceSearchVc = [[HQValanceSearchFourViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 5:{
            HQValanceSearchFiveViewController *valanceSearchVc = [[HQValanceSearchFiveViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 6:{
            HQValanceSearchSixViewController *valanceSearchVc = [[HQValanceSearchSixViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 7:{
            HQValanceSearchSevenViewController *valanceSearchVc = [[HQValanceSearchSevenViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 8:{
            HQValanceSearchEightViewController *valanceSearchVc = [[HQValanceSearchEightViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 9:{
            HQValanceSearchNineViewController *valanceSearchVc = [[HQValanceSearchNineViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 10:{
            HQValanceSearchTenViewController *valanceSearchVc = [[HQValanceSearchTenViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 11:{
            HQValanceSearchElevenViewController *valanceSearchVc = [[HQValanceSearchElevenViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        case 12:{
            HQValanceSearchTwelveViewController *valanceSearchVc = [[HQValanceSearchTwelveViewController alloc]init];
            valanceSearchVc.dataInfo = _dataSource[indexPath.row];
            [self.navigationController pushViewController:valanceSearchVc animated:YES];
        }break;
            
        default:
            break;
    }
}

/**
 搜索样式数据
 */
-(void)searchStyle{
    _collectionView.backgroundView = nil;
    [self showHudText:@""];
    [HQNetWork requetParam:nil withMethod:[HQMethod get_xl_lists] suc:^(NSDictionary *sucData) {
        [self hiddnHud];
        [_collectionView.mj_header endRefreshing];
        if([sucData[kStatus]integerValue] == 1){
            _dataSource = [[NSMutableArray alloc]initWithArray:sucData[@"data"]];
            if(_dataSource.count ==0){
                [self addNoneDataCollView:_collectionView withText:@"暂无样式数据，请新建样式"];
            }
            [_collectionView reloadData];
        }else{
            [self tostView:sucData[kInfo]];
        }
    } fail:^{
        [_collectionView.mj_header endRefreshing];
        [self hiddenErrorHud];
    }];
}

@end
